// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_HR_LEAVE_APPLICATION
// * CreateDate    : 2011/11/7 12:58:39
// * Creater       : CodeSmith
// * LastChangeDate: 2011/11/7 12:58:39
// * LastChanger   : 2011/11/7 12:58:39
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Hr
{
/// <summary>
    /// HrLeaveApplication
    /// </summary>
    public partial class HrLeaveApplicationBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objHrLeaveApplicationEntity">Entity</param>
        /// <returns>Entity</returns>
        public static HrLeaveApplicationEntity GetHrLeaveApplication(HrLeaveApplicationEntity objHrLeaveApplicationEntity)
        {
            return DataAccess.SelectSingle<HrLeaveApplicationEntity>(objHrLeaveApplicationEntity);
        }
        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"LA.*, P.NAME_CN AS PERSON_NAME, D.DEPARTMENT_NAME, 
                                (SELECT MP.POSITION_NAME + ';'
                                FROM MST_POSITION MP
                                INNER JOIN HR_PERSON_POSITION PP ON PP.POSITION_ID = MP.POSITION_ID
                                WHERE PP.PERSON_ID = P.PERSON_ID GROUP BY MP.POSITION_NAME FOR XML PATH('')) AS POSITION_NAME
                                FROM HR_LEAVE_APPLICATION LA
                                LEFT JOIN MST_PERSON P ON P.PERSON_ID = LA.PERSON_ID
                                LEFT JOIN MST_DEPARTMENT D ON D.DEPARTMENT_ID = LA.DEPARTMENT_ID
								LEFT JOIN MST_POSITION MP ON MP.POSITION_ID = LA.POSITIOIN_ID
                                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        public static HrLeaveApplicationEntity GetById(string appId)
        {
            if (string.IsNullOrEmpty(appId))
            {
                return null;
            }
            HrLeaveApplicationEntity entity = new HrLeaveApplicationEntity();
            entity.ApplicationId = appId;
            return DataAccess.SelectSingle<HrLeaveApplicationEntity>(entity);
        }
        public static DataSet GetLeaveApplicationForSalary(string salaryMonth, string personId)
        {
            if (string.IsNullOrEmpty(salaryMonth) || string.IsNullOrEmpty(personId))
            {
                return null;
            }
            if (salaryMonth.Length == 6)
            {
                salaryMonth = salaryMonth.Substring(0, 4) + "-" + salaryMonth.Substring(4);
            }
            string sql = @"SELECT * FROM HR_LEAVE_APPLICATION WHERE PERSON_ID = '" + personId + @"' 
                            AND (CONVERT(NVARCHAR(10),START_DATE,120) LIKE '%" + salaryMonth + "%' OR CONVERT(NVARCHAR(10),END_DATE,120) LIKE '%" + salaryMonth + "%') AND STATUS = 'LAS04'";
            return DataAccess.SelectDataSet(sql);
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objHrLeaveApplicationEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertHrLeaveApplication(HrLeaveApplicationEntity objHrLeaveApplicationEntity)
        {
            return DataAccess.Insert(objHrLeaveApplicationEntity);
        }

        public static bool InsertHrLeaveApplication(List<HrLeaveApplicationEntity> objHrLeaveApplicationEntityList)
        {
            return DataAccess.Insert(objHrLeaveApplicationEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objHrLeaveApplicationEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateHrLeaveApplication(HrLeaveApplicationEntity objHrLeaveApplicationEntity)
        {
            return DataAccess.Update(objHrLeaveApplicationEntity);
        }

        public static bool UpdateHrLeaveApplication(List<HrLeaveApplicationEntity> objHrLeaveApplicationEntityList)
        {
            return DataAccess.Update<HrLeaveApplicationEntity>(objHrLeaveApplicationEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objHrLeaveApplicationEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteHrLeaveApplication(HrLeaveApplicationEntity objHrLeaveApplicationEntity)
        {
            return DataAccess.Delete(objHrLeaveApplicationEntity);
        }

        public static bool DeleteHrLeaveApplication(List<HrLeaveApplicationEntity> objHrLeaveApplicationEntityList)
        {
            return DataAccess.Delete<HrLeaveApplicationEntity>(objHrLeaveApplicationEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetHrLeaveApplicationAll()
        {
            return DataAccess.SelectAllDataSet<HrLeaveApplicationEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<HrLeaveApplicationEntity> GetHrLeaveApplicationAllList()
        {
            return DataAccess.SelectAll<HrLeaveApplicationEntity>();
        }
        #endregion
	}
	
	
}	

